local tianyi = fk.CreateSkill {

  name = "joy__tianyi",

  tags = { Skill.Wake, },

}



tianyi:addEffect(fk.EventPhaseStart, {
  name = "joy__tianyi",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  frequency = Skill.Wake,
  can_trigger = function(self, event, target, player, data)
    return
      target == player and
      player.phase == Player.Start and
      player:hasSkill(tianyi.name) and
      player:usedSkillTimes(tianyi.name, Player.HistoryGame) < 1
  end,
  can_wake = function(self, event, target, player, data)
    return table.every(player.room.alive_players, function(p)
      return #player.room.logic:getActualDamageEvents( 1, function(e) return e.data.to == p end, Player.HistoryGame) > 0
    end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 2)
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = tianyi.name,
    })
    local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#mobile__tianyi-choose", tianyi.name, false)
    if #tos > 0 then
      room:handleAddLoseSkills(room:getPlayerById(tos[1]), "joy__zuoxing")
    end
  end,
})

return tianyi